<template>
	<view class="memberPermissionPage">
		<sunui-navbar :items="tabList" v-if="tabList.length>=1"  lineHeight="70rpx" :isCenter="true" :currentIndex="currentIndex"
			padding="0rpx" activeColor="rgb(0, 124, 255)" :size="112" activeLineBg="rgb(0, 124, 255)"
			textAlign="center" activeLineWidth="100%" activeDirection="space-between" activeLineHeight="4rpx"
			bgColor="transparent" :margin="30" @change="e=>getChanges(e,tabList)"></sunui-navbar>
		<block v-for="(item,index) in memberPermissiontArr" :key="index">
			<view class="memberPermissionList" v-if="memberPermissiontArr.length">
				<view class="flex-between padding-bottom_20rpx ">
					<view class="flex">
						<image class="image" :src="item.icon" mode=""></image>
						<view class="flex-columns-center margin-left_30rpx">
							<text class="font-weight_bold margin-bottom_10rpx" style="font-size: 30rpx;">{{item.name}}</text>
			
							<text style="color: rgb(80, 77, 78);font-size: 24rpx;text-align: left;">{{item.desc}}
							</text>
						</view>
					</view>
					<view class="flex-column-end margin-left_30rpx">
						<switch :checked="item.status==0?false:true" style="transform:scale(0.7)" @change="e=>switch1Change(e,item)" />
					</view>
				</view>
				<view class="flex-between">
					<view class="">
						<text style="color:rgb(153, 153, 153)">创建时间：{{item.create_time}}</text>
			
					</view>
					<view class="flex">
						<view style="color:rgb(153, 153, 153)" class="margin-right_30rpx flex" @click="editFn(item)">
							<uni-icons type="compose" size="17"></uni-icons>
							编辑
			
						</view>
			
					</view>
				</view>
			</view>
			
		</block>
		<view class="flex" style="height: 50vh;"  v-if="!memberPermissiontArr.length">
			<view class="flex-column">
				<image class="icon" src="/static/none1.png" mode=""></image>
				 空空如也
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				tabList:[],
				currentIndex:0,
				
				tabIndex: 4,
				memberPermissiontArr:[],
				token: uni.getStorageSync('login').token,
			}
		},
		onLoad() {
			this.templateListFn()
		},
		onShow() {
			this.init()
		},
		methods: {
			getChanges(e,item){
				
				console.log(e,item)
				this.template_id=item[e].id
				console.log(this.template_id)
				this.currentIndex=e
				this.init()
			},
			async templateListFn(){
				const res = await this.$http.post({
					url: this.$api.templateList,
					data: {
						page: 1,
						limit: 10,
				
					},
					headers: {
						'Authorization': `Bearer ${this.token}`
					}
				
				})
				if (res.code == 0) {
					
					this.tabList=res.data.map((item)=>{
						return{
							name:item.name,
							id:item.id
						}
					})
				
				} else {
					this.$sun.toast(res.msg, 'none')
				}
			},
              async init() {
              
              	const result = await this.$http.post({
              		url: this.$api.moduleList,
              		data: {
              			type: 2,
						template_id:this.template_id
              		},
              		headers: {
              			'Authorization': `Bearer ${this.token}`
              		}
              
              	})
              	if (result.code == 0) {
					
              		this.memberPermissiontArr = result.data.list
					console.log(this.memberPermissiontArr)
					
              	} else {
              		this.$sun.toast(result.msg, 'none')
              	}
              },
			  editFn(item){
				  this.$sun.navGo('/pages/memberPermission/memberPermissionEdit/memberPermissionEdit',{...item})
			  },
			  async switch1Change(e, item) {
			  	console.log('switch1 发生 change 事件，携带值为', e.detail.value)
			  
			  
			  	const result = await this.$http.post({
			  		url: this.$api.upModuleStatus,
			  		data: {
			  			id: item.id,
			  			status: item.status == 0 ? 1 : 0
			  
			  		},
			  		headers: {
			  			'Authorization': `Bearer ${this.token}`
			  		}
			  
			  	})
			  	if (result.code == 0) {
			  		this.init()
			  		this.$sun.toast(result.msg, 'none')
			  	} else {
			  		this.$sun.toast(result.msg, 'none')
			  	}
			  },
		}
	}
</script>

<style lang="less" scoped>
	page {
		background: #fff;
	}
   .icon{
	   width: 250rpx;
	   height: 80px;
   }
	.memberPermissionPage {
		padding: 20rpx;


		.memberPermissionList {
			margin-top: 20rpx;
			padding: 20rpx;
			background: rgb(245, 248, 255);

			.image {
				width: 76rpx;
				height: 76rpx;

			}
		}

	}
</style>